﻿@using Smartstore.Web.Models.Catalog

@model ProductReviewOverviewModel

@{
    if (!Model.AllowCustomerReviews)
    {
        return;
    }

    var ratingPercent = Model.TotalReviews != 0
        ? ((Model.RatingSum * 100) / Model.TotalReviews) / 5
        : 0;
    var ratingValue = (ratingPercent / (decimal)20).ToString("0.0", CultureInfo.GetCultureInfo("en-US"));
    var ratingLabel = T(Model.TotalReviews == 1 ? "Reviews.Overview.Review" : "Reviews.Overview.Reviews", ratingValue, Model.TotalReviews);
    var reviewPageUrl = Url.Action("Reviews", new { id = Model.ProductId });
}

<div class="pd-review-summary pd-group" @Html.Raw(Model.TotalReviews > 0 ? " itemprop='aggregateRating' itemscope itemtype='http://schema.org/AggregateRating'" : string.Empty)>
    @* STARS *@
    <div class="pd-rating-box">
        <div role="img" class="rating" aria-label="@ratingLabel">
            <div style="width: @(ratingPercent)%"></div>
        </div>
        <span sm-if="Model.TotalReviews > 0" class="pd-review-count">
            (<a href="@reviewPageUrl" aria-label="@ratingLabel" attr-aria-describedby='(Model.Reward != null, "pd-points-for-review")'>@Model.TotalReviews</a>)
        </span>
    </div>

    @* TEXT *@
    <div class="pd-review-link link-dnu">
        @if (Model.TotalReviews > 0)
        {
            <a href="@reviewPageUrl" class="link-dnu" attr-aria-describedby='(Model.Reward != null, "pd-points-for-review")'>@T("Reviews.Overview.AddNew")</a>
            @* Hidden microdata info *@
            <meta itemprop="ratingValue" content='@ratingValue' />
            <meta itemprop="reviewCount" content='@Model.TotalReviews' />
            <meta itemprop="ratingCount" content='@Model.TotalReviews' />
        }
        else
        {
            <a href="@reviewPageUrl" class="link-dnu" attr-aria-describedby='(Model.Reward != null, "pd-points-for-review")'>@T("Reviews.Overview.First")</a>
        }
    </div>
    <div sm-if="Model.Reward != null" id="pd-points-for-review" class="pd-review-amount alert alert-success mt-1 fs-sm py-2 w-100">
        @Html.Raw(T("RewardPoints.Message.RewardPointsForProductReview", Model.Reward.Points, Model.Reward.Amount.ToString()))
    </div>
</div>